package com.yuhuihui.common.utils;

import com.yuhuihui.common.domain.result.ResponseResult;
import com.yuhuihui.common.enums.ResultCodeStatusEnum;

/**
 * 返回信息工具类
 *
 * @author yuhh
 * @date 2023-05-25 14:41:17
 */
public final class ResultUtil {

    /**
     * 返回成功信息
     *
     * @param data 成功信息
     * @return {@link ResponseResult }<{@link T }>
     * @author yuhh
     * @date 2023-05-25 14:41:21
     */
    public static <T> ResponseResult<T> success(T data){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(ResultCodeStatusEnum.OK.code);
        result.setMsg("成功");
        result.setData(data);
        return result;
    }

    /**
     * 返回成功信息
     *
     * @param data 成功信息
     * @param msg  返回消息
     * @return {@link ResponseResult }<{@link T }>
     * @author yuhh
     * @date 2025-06-12 13:39:16
     */
    public static <T> ResponseResult<T> success(T data, String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(ResultCodeStatusEnum.OK.code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    /**
     * 返回失败信息
     *
     * @param data 失败信息
     * @return {@link ResponseResult }<{@link T }>
     * @author yuhh
     * @date 2023-05-25 14:41:29
     */
    public static <T> ResponseResult<T> error(T data){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(ResultCodeStatusEnum.FAIL.code);
        result.setMsg("失败");
        result.setData(data);
        return result;
    }

    /**
     * 返回失败信息
     *
     * @param data       失败信息
     * @param resultCode 返回code
     * @return {@link ResponseResult }<{@link T }>
     * @author yuhh
     * @date 2025-06-12 12:01:04
     */
    public static <T> ResponseResult<T> error(T data, ResultCodeStatusEnum resultCode){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(resultCode.code);
        result.setMsg("失败");
        result.setData(data);
        return result;
    }


    /**
     * 返回失败信息
     *
     * @param data       失败信息
     * @param resultCode 返回code
     * @param msg        返回消息
     * @return {@link ResponseResult }<{@link T }>
     * @author yuhh
     * @date 2025-06-12 12:01:44
     */
    public static <T> ResponseResult<T> error(T data, ResultCodeStatusEnum resultCode, String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(resultCode.code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    private ResultUtil(){

    }
}
